package javabook.ch07;

import java.awt.Button;
import java.awt.Canvas;
import java.awt.Checkbox;
import java.awt.CheckboxGroup;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.Label;
import java.awt.Scrollbar;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentListener;
import java.awt.event.ItemListener;

public class todo01 extends Frame implements ActionListener, ItemListener, AdjustmentListener{
	
	Checkbox ch, da, so, se, je;
	Checkbox gch, gda, gso, gse, gje;
	CheckboxGroup cbg;
	Label label1, label2, label3, label4, label5, lb0;
	Scrollbar vSlider, hSlider;
	Canvas imgCanvas;
	Button bt0, bt1, bt2, bt3, bt4, btnexit;
	String msg1 = " ";
	String msg2 = " ";
	TextField tx;
	
	public todo01(){
		super ("버튼 / 텍스트 필드 생성과 이벤트 처리 ");
		setLayout(new FlowLayout());
		
		label1 = new Label("당신이 좋아하는 지명을 선택하기 바랍니다. ", Label.CENTER);
		add(label1);
		
		bt0 = new Button("천안");
		bt1 = new Button("당진");
		bt2 = new Button("속초");
		bt3 = new Button("서울");
		bt4 = new Button("제주");
		add(bt0);
		add(bt1);
		add(bt2);
		add(bt3);
		add(bt4);
		
		tx = new TextField(20);
		add(tx);
		btnexit = new Button("종료");
		add(btnexit);
		
		setSize(700, 300);
		setVisible(true);
		
		EvenHandler eh = new EvenHandler();
		bt0.addActionListener(eh);
		bt1.addActionListener(eh);
		bt2.addActionListener(eh);
		bt3.addActionListener(eh);
		bt4.addActionListener(eh);
		btnexit.addActionListener(eh);
	}

	
	public class EvenHandler implements ActionListener{
		public void actionPerformed(ActionEvent ae){
			String cap = ae.getActionCommand();
			String msg = "선택한 지명 : ";
			if(cap == "천안"){
				tx.setText(msg + cap);}
			if(cap == "당진"){
				tx.setText(msg + cap);}
			if(cap == "속초"){
				tx.setText(msg + cap);}
			if(cap == "서울"){
				tx.setText(msg + cap);}
			if(cap == "제주"){
				tx.setText(msg + cap);}
			if(cap.equals("종료")){
				System.exit(0);}
			
		}
	}
	
	public static void main(String[] args) {
		todo01 todo = new todo01();
	}
	
}
